package com.xy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2//启用S​​wagger 2
public class SwaggerConfig {

    //配置Swagger的docket()的bean实例
    @Bean
    public Docket docket(){
        return new Docket(
                DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()
                ).select()
                //basePackage("com.xy.controller")扫描指定包
                //any()扫描全部
                //none()都不扫描
                //withClassAnnotation(RestController.class)扫描类上面指定注解
                //withMethodAnnotation扫描方法上的指定注解
                .apis(RequestHandlerSelectors.basePackage("com.xy.controller"))
                //.paths(PathSelectors.ant("/ziyi/**"))指定过滤路径
                .build();
    }

    //配置Swagger基础信息
    public ApiInfo apiInfo(){
        Contact contact = new Contact("吴心意","https://www.baidu.com/","1597719669@qq.com");
        return new ApiInfo(
                "恣意的SwaggerAPI文档",
                "我宁愿犯错，也不愿什么都不做",
                "v1.0",
                "https://www.baidu.com/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
